class A:
    def __enter__(self):
        ##使用了with之后就会使用enter来创建对象，此时需要返回对象才行
        print('begin A')
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        print('exit is running')

    def __init__(self,num):
        self.num = num

    def show(self):
        print(self.num)

if __name__ == '__main__':
    a = A(10)
    a.show()
    print("*"*100)
    with A(20) as aa:
        aa.show()